package com.core.website.api;

import com.core.website.common.Result;
import com.core.website.common.ResultUtil;
import com.core.website.entity.Content;
import com.core.website.entity.CoreDutyRecordInfo;
import com.core.website.entity.User;
import com.core.website.service.ContentService;
import com.core.website.service.CoreDutyRecordInfoService;
import com.core.website.util.IpAddressUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * 值班日记相关接口
 */
@RestController
@RequestMapping("/dutyRecordInfoApi")
public class CoreDutyRecordInfoApi {
    @Autowired
    private CoreDutyRecordInfoService dutyRecordInfoService;
    @PostMapping("/add")
    public Result add(@RequestBody CoreDutyRecordInfo dutyRecordInfo){

        User subject = (User) SecurityUtils.getSubject().getPrincipal();
        if(null==subject){
            return ResultUtil.error(-1000,"用户未登录");
        }
        String result=dutyRecordInfoService.insertCoreDutyRecordInfo(dutyRecordInfo);
        return ResultUtil.success(result);
    }

    @GetMapping(value = "/getInfoByCid/{contentId}")
    public Result getInfoByCid(@PathVariable("contentId") String contentId){
        CoreDutyRecordInfo dutyRecordInfo = dutyRecordInfoService.selectCoreDutyRecordInfoByContentId(contentId);
        return ResultUtil.success(dutyRecordInfo);
    }
}
